/* JORGE FERNANDO GOMEZ
 * 1259371
 * 189631
 * LEC A1
 * MARTIN MÜLLER
 * D02
 * YANG LIU
 */

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include "draw1b.h"

char * myKeywords[] = {"Figure", "draw", "End", "printFigure", "drawFigure",
                       "translate", "child"};

int main (int argc, char * argv[]) {

    /* Checks for an command line argument */
    if ( argc < 2 ) {
        fprintf(stderr,
                "You need to enter an input file to run this program.\n");
        exit(EXIT_FAILURE);
    }

    size_t program_length = strlen(argv[0]);
    char program[program_length+1];
    strncpy(program, argv[0], program_length+1);

    /* Welcome message */
    printf("%s started on ", program);
    fflush(NULL);
    system("date");
    printf("Input file: ./%s\n", argv[1]);


    /* Read in the file */
    Line * Lines;
    FILE * inputFile;
    long inputFileLength;
    inputFile = fopen(argv[1], "r");

    if ( inputFile == NULL ) {
        fprintf(stderr, "Failed to open specified input file: %s\n", argv[1]);
        exit(1);
    }

    char buff[MAXLEN];
    for ( inputFileLength = 0; fgets(buff, MAXLEN+1, inputFile) != NULL;) {
        inputFileLength++;
    }

    Lines = (Line*) malloc(sizeof(Line) * inputFileLength);
    char ** myComments = malloc(sizeof(char) * inputFileLength);
    for (int i = 0; i < inputFileLength; i++) {
        myComments[i] = (char *) malloc(sizeof(char) * (MAXLEN+1));

        if (myComments[i] == NULL) {
            fprintf(stderr, "malloc failure\n");
            exit(EXIT_FAILURE);
        }
    }


    /* Read the input and store it */
    if ( !(readInput(inputFile, Lines, &inputFileLength)) ) {
        fprintf(stderr, "Could not read in file.\n");
        exit(EXIT_FAILURE);
    }
    else {
        printf("Read file.\n");
    }

    processLines(Lines, inputFileLength);





    return(EXIT_SUCCESS);
}
